package com.linln.modules.shopsService.repository;

import com.linln.modules.shopsService.domain.Shops;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.modules.shopsService.repository
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.modules.shopsService.repository
 * @Description: TODO
 * @date Date : 2020年12月09日 15:20
 */
public interface ShopReviewedRepository extends JpaRepository<Shops, String> {
    //通过状态获取店铺
    @Query(nativeQuery = true, value = "select * from tbl_shop as ts where ts.del_flag = '0' and audit_mark = ?1 and if(?2 !='',(shop_name like %?2% or contacts_name like %?2%),1=1)"
            , countQuery = "SELECT count(0) FROM `tbl_shop` where  audit_mark = ?1 and if(?2 !='',(shop_name like %?2% or contacts_name like %?2%),1=1)")
    Page<Shops> getShopsByStatus(@Param("status") Integer status, String searchName, @Param("page") Pageable pageable);

    //审核方法 修改审核状态
    @Modifying
    @Query(nativeQuery = true, value = "update tbl_shop set audit_mark = ?2,props = JSON_SET(props, '$.reviewedOpinion', ?3) where shop_id = ?1")
    void updateReviewedStatus(String shopId, Integer reviewedStatus, String reviewedOpinionText);


    //获取店铺类型
    @Query(nativeQuery = true, value = "\t\t\t\t\t\t\t\t\t\t\t\t\n" +
            "SELECT\n" +
            "\tgroup_concat(service_type_name)\n" +
            "FROM\n" +
            "\ttbl_service_type\n" +
            "WHERE \n" +
            "\n" +
            " service_type_id REGEXP (\n" +
            "\tSELECT\n" +
            "\t\tCONCAT('^',REPLACE (shop_type, ',', '$|^'),'$')\n" +
            "\tFROM\n" +
            "\t\ttbl_shop\n" +
            "\tWHERE\n" +
            "\t shop_id = ?1\n" +
            ")"
    )
    String selectShopType(@Param("shopId") String shopId);

}
